package jin.competition.jan08;

public class ThreeArrays {
	public static void bubbleSort(int test[]) {// 冒泡排序，降序排列
		for (int i = 0; i < test.length; i++) {
			for (int j = i + 1; j < test.length; j++) {
				if (test[i] < test[j]) {
					int temp = test[i];
					test[i] = test[j];
					test[j] = temp;
				}
			}
		}
	}

	public static void selectionSort(int test[]) {// 选择排序升序排列
		int temp;
		for (int i = 0; i < test.length; i++) {
			// 代表这轮的排序，最终会找出把最小值放在lowIndex位置。
			int lowIndex = i;
			// 找出最小值的，下标
			for (int j = i + 1; j < test.length; j++) {
				if (test[j] < test[lowIndex]) {
					lowIndex = j;
				}
			}
			// 最小下标的和i交换位置。
			temp = test[i];
			test[i] = test[lowIndex];
			test[lowIndex] = temp;
		}
	}

	public static void print(int temp[]) {
		for (int i = 0; i < temp.length; i++) {
			System.out.print(temp[i] + "\t");
		}
		System.out.println();
	}

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		ArrayOne oneArr1 = new ArrayOne();
		oneArr1.setNum1(67);
		oneArr1.setNum2(87);
		ArrayOne oneArr2 = new ArrayOne();
		oneArr2.setNum1(66);
		oneArr2.setNum2(32);
		ArrayOne oneArr3 = new ArrayOne();
		oneArr3.setNum1(12);
		oneArr3.setNum2(331);

		int arr1[] = { oneArr1.getNum1(), oneArr1.getNum2() };
		int arr2[] = { oneArr2.getNum1(), oneArr2.getNum2() };
		int arr3[] = { oneArr3.getNum1(), oneArr3.getNum2() };
		int p1 = oneArr1.add(arr1);
		int p2 = oneArr2.add(arr2);
		int p3 = oneArr3.add(arr3);
		System.out.println("未排序：");
		System.out.println(p1+"\t"+p2+"\t"+p3);

		int sumArr[] = { p1, p2, p3 };

		bubbleSort(sumArr);
		System.out.println("冒泡排序，降序排列:");
		print(sumArr);
		selectionSort(sumArr);
		System.out.println("选择排序升序排列:");
		print(sumArr);

	}

}
/*
 * 2. 有三个数组，里面分别存了，(67,87),(66,32),(12,331).
 * 分别计算数组里面两个元素的和，并且对和，用冒泡排序，降序排列。用选择排序升序排列。
 */